package com.wyzz.hr.bo.impl;

import java.util.LinkedList;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.wyzz.hr.bo.IEmpAddConfBo;
import com.wyzz.hr.dao.IEmpAddConfDAO;
import com.wyzz.hr.pojo.Empaddconf;

public class EmpAddConfBoImpl implements IEmpAddConfBo {

	public EmpAddConfBoImpl() {
	}

	public List listAll() {
		String hql = "from Empaddconf order by eadcSeq";
		List results = empAddConfDAO.exeHqlList(hql);
		return results;
	}

	public List listByTable(String tableName) {
		String hql = (new StringBuilder()).append(
				"from Empaddconf where eadcTableName = '").append(tableName)
				.append("' order by eadcSeq").toString();
		List results = empAddConfDAO.exeHqlList(hql);
		return results;
	}

	public void deleteEmpaddconf(String id) {
		empAddConfDAO.deleteObject(com.wyzz.hr.pojo.Empaddconf.class, id);
	}

	public void insertEmpaddconf(Empaddconf conf) {
		empAddConfDAO.saveObject(conf);
	}

	public Empaddconf loadEmpaddconf(String id) {
		Empaddconf conf = (Empaddconf) empAddConfDAO.loadObject(
				com.wyzz.hr.pojo.Empaddconf.class, id, null, new boolean[0]);
		return conf;
	}

	public List listAllActiveFields() {
		List fields = new LinkedList();
		for (int i = 1; i <= 16; i++)
			fields.add(Integer.valueOf(i));

		List fieldList = null;
		String hql = "select eadcSeq from Empaddconf";
		fieldList = empAddConfDAO.exeHqlList("select eadcSeq from Empaddconf");
		if (fieldList != null) {
			int size = fieldList.size();
			for (int i = 0; i < size; i++)
				fields.remove(fieldList.get(i));

		}
		return fields;
	}

	public List listAllActiveFieldsByTable(String tableName, Integer number) {
		List fields = new LinkedList();
		for (int i = 1; i <= number.intValue(); i++)
			fields.add(Integer.valueOf(i));

		List fieldList = null;
		String hql = (new StringBuilder()).append(
				"select eadcSeq from Empaddconf where eadcTableName = '")
				.append(tableName).append("'").toString();
		fieldList = empAddConfDAO.exeHqlList(hql);
		if (fieldList != null) {
			int size = fieldList.size();
			for (int i = 0; i < size; i++)
				fields.remove(fieldList.get(i));

		}
		return fields;
	}

	public List findByName(String fieldName) {
		DetachedCriteria dc = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empaddconf.class);
		dc.add(Restrictions
				.eq(Empaddconf.PROP_EADC_TABLE_NAME, "empadditional"));
		dc.add(Restrictions.eq(Empaddconf.PROP_EADC_FIELD_NAME, fieldName
				.trim()));
		return empAddConfDAO.findByCriteria(dc);
	}

	public List findByConf(Empaddconf conf) {
		DetachedCriteria dc = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empaddconf.class);
		dc.add(Restrictions.eq(Empaddconf.PROP_EADC_TABLE_NAME, conf
				.getEadcTableName().trim()));
		dc.add(Restrictions.eq(Empaddconf.PROP_EADC_FIELD_NAME, conf
				.getEadcFieldName().trim()));
		return empAddConfDAO.findByCriteria(dc);
	}

	public List findByTableName(String tableName) {
		DetachedCriteria dc = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empaddconf.class);
		dc.add(Restrictions.eq(Empaddconf.PROP_EADC_TABLE_NAME, tableName
				.trim()));
		return empAddConfDAO.findByCriteria(dc);
	}

	public void updateEmpaddconf(Empaddconf conf) {
		empAddConfDAO.updateObject(conf);
	}

	public IEmpAddConfDAO getEmpAddConfDAO() {
		return empAddConfDAO;
	}

	public void setEmpAddConfDAO(IEmpAddConfDAO empAddConfDAO) {
		this.empAddConfDAO = empAddConfDAO;
	}

	private static final int NUMBER = 16;
	IEmpAddConfDAO empAddConfDAO;
}
